package com.itheima.stock.get;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpEntity;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

/**
 * @author fantuan
 * @created 2025/11/13 19:57
 * @description
 */
@SpringBootTest
public class GetDataFromSina {
    @Autowired
    private RestTemplate restTemplate;


    @Test
    void testGetDataFromSina() {
        String url = "https://hq.sinajs.cn/list=s_sh000001";
        HttpMethod method = HttpMethod.GET;
        HttpHeaders header = new HttpHeaders();
        header.add("Referer","https://finance.sina.com.cn");
        header.add("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36");
        HttpEntity<?> entity = new HttpEntity<>(header);
        ResponseEntity<String> exchange = restTemplate.exchange(url, method, entity, String.class);
        String body = exchange.getBody();
        System.out.println(body);
    }
}
